#!c:/perl/bin/perl.exe

use DBI;
use DBD::mysql;
use DIVA_DB;
use WWCOM;
use CGI;
use strict;
	
my $DEBUG= 1;
$DIVA_DB::DEBUG= $DEBUG;

$DIVA_DB::DATABASE_NAME= "wwcom";
$DIVA_DB::DATABASE_SERVER= "localhost:3306";

my $cgi= new CGI;
my %outvars;

my @names= <$WWCOM::SITEBASEDIR/players/*.html>;

my %allstories;
my $cols= ['PLAYER_NAME','PLAYER_PROFILE','PLAYER_HEIGHT','PLAYER_WEIGHT','PLAYER_DATEOFBIRTH','PLAYER_PLACEOFBIRTH','FK_OBJECT_ID'];
my $vals;

my $dbh= &DIVA_DB::DB_CONNECT('root','FineBob+');
my $count= 0;
for(my $i= 0; $i<$#names; $i++) {
	open(FH,$names[$i]);
	my @data= <FH>;
	close FH;
	my $data= join('',@data);
	
	if ($data=~ /<h2>(.*?)<\/h2>/i) {
		$$vals[$count][0]= $1;
	} else {
		$$vals[$count][0]= '';
	}
	if ($data=~ /<div class=player>(.*?)<\/div>/si) {
		$$vals[$count][1]= $1;
	} else {
		$$vals[$count][1]= '';
	}
	if ($data=~ /Height: (.*?)\n/i) {
		$$vals[$count][2]= $1;
	} else {
		$$vals[$count][2]= '';
	}
	if ($data=~ /Weight: (.*?)\n/i) {
		$$vals[$count][3]= $1;
	} else {
		$$vals[$count][3]= '';
	}
	if ($data=~ /Date of Birth: (.*?)\/(.*?)\/(.*?)\n/i) {
		my $db_date= "$3-$2-$1";
		$$vals[$count][4]= $db_date;
	} else {
		$$vals[$count][4]= '';
	}
	if ($data=~ /Place of Birth: (.*?)\n/i) {
		$$vals[$count][5]= $1;
	} else {
		$$vals[$count][5]= '';
	}

	&DIVA_DB::INSERT_DATA($dbh,$cgi,\%outvars,'OBJECT',['FK_CONTENTTYPE_ID','OBJECT_DATE'],[[1,'NOW()']]);
	$$vals[$count][6]= $dbh->{'mysql_insertid'};
	&DIVA_DB::INSERT_DATA($dbh,$cgi,\%outvars,'PLAYER',$cols,$vals);
}
	
